#include "json.hpp"
#include <iostream>

using json = nlohmann::json;

void merge_json(json& reference, json& result)
{
    result.merge_patch(reference);
}

int main()
{
    json j = { {"method", "A"}, { "detailA", "B" }, {"OK", true} }, j2;
    std::cout << j << std::endl;
    j["OK"] = false; // change value
    j["method"] = 1; // change data type
    j["newitem"] = "1"; // new item
    std::cout << std::setw(4) << j << std::endl; // pretty view
    // expand a c-style const string
    const char* newitem = std::string(j["newitem"]).c_str();
    std::cout << newitem << std::endl;
    // find && add an item
    if(j.find("ss") == j.end())
    {
        j["ss"] = 1;
    }
    std::cout << j << std::endl;
    j2 = { {"method", "C"}, {"new", true} };
    merge_json(j2, j);
    std::cout << j << std::endl;
    printf("%s\n", j.dump().c_str());
    return 0;
}
